﻿@model Controller2.Models.RegisterModel
@{
    ViewBag.Title = "Inclusão de Usuário";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<style type="text/css">
    .editor-label
    {
        width: 170px;
    }
    #formHide
    {
        margin: 30px auto 50px auto;
    }
</style>
<div id="formHide">
    @{string tipo = ViewBag.Request ?? "";}
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
    
        <fieldset>
            <legend>Informações da Conta</legend>
            <div class="editor-label">
                @Html.LabelFor(m => m.UserName, "Nome de usuário: ")
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Email, "E-mail: ")
            </div>
            <div class="editor-field">                
                @Html.TextBoxFor(m => m.Email)
                @Html.ValidationMessageFor(m => m.Email)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Password, "Senha: ")
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.ConfirmPassword, "Confirmação de senha: ")
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.ConfirmPassword)
                @Html.ValidationMessageFor(m => m.ConfirmPassword)
            </div>
        @if (tipo.Equals("Novo"))
        {
            <div class="editor-label">
                &nbsp;
            </div>
		    <div class="editor-field">
                @Html.RadioButtonFor(model => model.Role, "Administrador", new { id = "Administrador" })
                @Html.Label("Administrador")
                @Html.RadioButtonFor(model => model.Role, "Gerente", new { id = "Gerente" })
                @Html.Label("Gerente")
            </div>
        }   
        </fieldset>
        <div id="botoesForm">
            <input type="submit" id="Gravar" value="Gravar" />
            <input type="button" id="Fechar" value="Cancelar" />
        </div>
    
    }
</div>
<script type="text/javascript">
    $(function () {
        $('#UserName').val('');
        if ('@tipo' == "Novo") {
            $('#Email').val('');
            $('#Administrador').attr('checked', 'checked');
        } else {
            $('#Email').val('@ViewBag.Email');
        }
        $('#Password').val('');
        $('#ConfirmPassword').val('');
        $('#formHide').fadeIn('slow');
        hideLoading();
        $('#UserName').focus();
    });
    $('#Fechar').click(function () {
        switch ('@ViewBag.Request') {
            default:
                window.location.href = '@Url.Action("Index")';
                break;
            case "Cliente":
                window.location.href = '@Url.Action("Index", "Cliente")';
                break;
            case "Funcionario":
                window.location.href = '@Url.Action("Index", "Funcionario")';
                break;
        }
    });
</script>
